import Vue from 'vue'
import App from './App.vue'
import router from './router';
Vue.config.productionTip = false
import Map from 'ol/Map';

if (Map.prototype.getLayerByName === undefined) {
  Map.prototype.getLayerByName = function (name) {
    let layer;
    this.getLayers().forEach(function (lyr) {
      if (name == lyr.name) {
        layer = lyr;
      }
    });
    return layer;
  };
}
if (Map.prototype.addLayerEvent === undefined) {
  Map.prototype.addLayerEvent = function ({ map, layerName, listener, eventName }) {
    eventName = eventName || 'singleclick'
    const eventKey = map.on(eventName, (e) => {
      map.forEachLayerAtPixel(
        e.pixel,
        () => {
          listener(e)
        },
        {
          layerFilter: (e) => {
            return e.name === layerName
          },
          hitTolerance: 200,
        }
      );
    });
    return eventKey;
    // map.unByKey(key);
  }
}



new Vue({
  router,
  render: h => h(App),
}).$mount('#app')
